package edu.sfsu.powerrangers.jeopardy.editor;

import java.awt.BorderLayout;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class ValuePanel extends JPanel {
	private static final long serialVersionUID = 1L;
	
	private JTextField valueField;
	
	public ValuePanel() {
		JLabel dollarLabel = new JLabel("$");
		valueField = new JTextField(6);
		JPanel valuePanel1 = new JPanel(new BorderLayout(4,4));
		valuePanel1.add(dollarLabel, BorderLayout.LINE_START);
		valuePanel1.add(valueField, BorderLayout.CENTER);
		JLabel valueLabel = new JLabel("Value:");
		valueLabel.setHorizontalAlignment(JLabel.CENTER);
		JPanel valuePanel2 = new JPanel(new BorderLayout(4,4));
		valuePanel2.add(valueLabel, BorderLayout.PAGE_START);
		valuePanel2.add(valuePanel1, BorderLayout.CENTER);
		valuePanel2.setMaximumSize(valuePanel2.getPreferredSize());
		setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
		add(Box.createVerticalGlue());
		add(valuePanel2);
		add(Box.createVerticalGlue());
	}
	
	public int getValue() {
		try {
			return Integer.parseInt(valueField.getText());
		} catch (NumberFormatException nfe) {
			return 0;
		}
	}
	
	public void setValue(int value) {
		valueField.setText(Integer.toString(value));
	}
}
